package model

import "time"

type ClassifyModel struct {
	Id         int       `json:"id" gorm:"type:int(11) auto_increment; NOT NULL; primary_key"`
	Title      string    `json:"title" gorm:"type:varchar(255); COMMENT:'类型名称'"`
	ParentId   int       `json:"parent_id" gorm:"type:int(11); COMMENT:'父级类型id'"`
	Type       string    `json:"type" gorm:"type:varchar(32); COMMENT:'类型'"`
	ParentPath string    `json:"parent_path" gorm:"type:varchar(255); COMMENT:'父级路径'"`
	CreatedAt  time.Time `json:"created_at" gorm:"type:timestamp"`
	UpdatedAt  time.Time `json:"updated_at" gorm:"type:timestamp"`
}

func (ClassifyModel) TableName() string {
	return "classify"
}

func (ClassifyModel) GetClassifyTitle(id int) string {
	var classify ClassifyModel
	if err := GetInstance().DB.Where("id = ?", id).First(&classify).Error; err != nil {
		return ""
	}
	return classify.Title
}
